package com.zui.webapp.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;

import com.zui.manager.SessionManager;
import com.zui.security.User;
import com.zui.util.JqGridPage;

@SuppressWarnings({"unchecked","rawtypes"})
public class SetupAction extends BaseJQGridAction {

	private static final long serialVersionUID = 1L;
	private static final Log log = LogFactory.getLog(SetupAction.class);
	
	private List<User> userList;
	public SetupAction() {}
	public SetupAction(SessionManager sessionManager) {
		this.sessionManager = sessionManager;
	}
	private SessionManager sessionManager;
	public void setSessionManager(SessionManager sessionManager) {
		this.sessionManager = sessionManager;
	}

//	/***********************************************************
//	 * JQGrid Pagination start
//	 **********************************************************/
//	/**
//	 *  current page number
//	 */
//	private Integer page = 0;
//	public Integer getPage() {return jq.getRequestPage();}
//	public void setPage(Integer page) {this.page = page;	}
//	/**
//	 * total page number
//	 */
//	private Integer total = 0;
//	public Integer getTotal() {return total;}
//	public void setTotal(Integer total) {this.total = total;}
//	/**
//	 *  total records number
//	 */
//	private Integer records = 0;
//	public Integer getRecords() {return records;}
//	public void setRecords(Integer records) {
//		this.records = records;
//		if (this.records > 0 && jq.getPageSize() > 0) {
//			this.total = (int) Math.ceil((double) this.records
//					/ (double) jq.getPageSize());
//		} else {
//			this.total = 0;
//		}
//	}

	/***********************************************************
	 * Business Method start
	 **********************************************************/
	public String index() {
		log.debug("index() method in class SetupAction is executed!");
		return "index";
	}
	public String usersIndex() {
		log.debug("usersIndex() method in class PersonAction is executed!");
		return "usersIndex";
	}
	public String usersJsonList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
		if (jq !=null && jq.get_search()) {
			log.debug("defulat search launched for " + User.class
					+ ",searchField:" + jq.getSearchField() + ",searchOper:"
					+ jq.getSearchOper() + ",searchString:"
					+ jq.getSearchString());
		}

		log.debug("usersJsonList() method in class PersonAction is executed!");
		userList = sessionManager.findByCriteriaForJQGrid(criteria,jq == null ? jq = new JqGridPage()
		: jq);
		return "usersJsonList";
	}

	/***********************************************************
	 * getters and setters
	 **********************************************************/
	/**
	 * @return the userList
	 */
	public List<User> getUserList() {
		return userList;
	}
	/**
	 * @param userList the userList to set
	 */
	public void setUserList(List<User> userList) {
		this.userList = userList;
	}
}
